package com.sinotrust.classify;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.sql.DataSource;

import org.kernelab.basis.Tools;

import com.sinotrust.classify.algorithm.SVMAlgorithm;
import com.sinotrust.classify.mba.DefaultMba;
import com.sinotrust.classify.mba.MbaManager;

public class AlgorithmManager {
	private static Map<String, String> classMap;

	private static String SVM_CLASS_NAME = "com.sinotrust.classify.algorithm.SVMAlgorithm";

	public static void init() {
		classMap = new HashMap<String, String>();
		classMap.put("SVM", SVM_CLASS_NAME);
	}
	public static DefaultAlgorithm lookup(String key){
		String className = classMap.get(key);		
		try {
			return (DefaultAlgorithm)Class.forName(className).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
			throw new IllegalAlgorithmException("");
		} catch (IllegalAccessException e) {
			e.printStackTrace();
			throw new IllegalAlgorithmException("");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			throw new IllegalAlgorithmException("");
		}
	}
	public static void  main(String [] args) throws IOException{
		AlgorithmManager.init();
		MbaManager.init();
//		Tools.debug(MbaManager.lookup("SVM").getModel());
		AlgorithmManager.lookup("SVM").predict("dataSvmTest.txt",MbaManager.lookup("SVM").getModel(),0.8);
	}	
}
